<?php
class Admin_Home_Model_ListModule extends AbstractModel{
	public function browse(){
		$db = new AbstractDB();
		//id and list of all position of current template
		$template = $db->select("id,str_positions","template","int_using = 1");
		$positions = mysql_fetch_row($template);
		
		//list all module, which are available for current template
		$module = $db->select("name,status,position","module","int_templateId = ".$positions[0]);				
		$result = array();
		while($row = mysql_fetch_row($module)){
			$result[] = $row;
		}
		$result["listPos"] = explode(",",$positions[1]);
		return $result;
	}
	
	public function updateModule($data,$where,$modulename){
		//update to db
		$db = new AbstractDB();		
		$module = $db->update("module",$data,$where);
		//update to config file
		$sysConf = new SystemConfig();
		$config = $sysConf->getConfig("basic.ini");
		$config["module"][$modulename][0] = $data["status"];
		// "'" filter for string type
		$config["module"][$modulename][1] = str_replace("'", "", $data["position"]);
		$sysConf->saveChangedConfig($config,"basic.ini");
		return 	$module;	
	}
}